package com.sziit.se.highconcurrency.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    private SecurityInterceptor securityInterceptor;

    public WebMvcConfig(){}

    @Autowired
    public  WebMvcConfig(SecurityInterceptor securityInterceptor){
        this.securityInterceptor = securityInterceptor;
    }
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration interceptor = registry.addInterceptor(securityInterceptor);
        /*配置拦截路径*/
        interceptor.addPathPatterns("/**");
        /*配置不拦截路径*/
        interceptor.excludePathPatterns("/error");
    }

    @Override
    protected void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(new CurrentUserResolver());
    }
}